package com.m1905.lib.download.sample;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.m1905.lib.download.DownloadManager;
import com.m1905.lib.download.listener.OnCmdCompletedListener;
import com.m1905.lib.download.model.DownloadDBItem;
import com.m1905.lib.download.util.DLog;
import com.m1905.lib.download.util.DownloadPreferences;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        DLog.setLogEnable(true);
        DownloadPreferences.init(this, null);
        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DownloadDBItem item = new DownloadDBItem.Builder().setDownloadId("10").setTitle("xxx.apk").setUrl("https://pay.cnki.net/cnkiclientapp/CNKIClient_Version8.8.1.apk").builder();
                DownloadManager.getInstance().startDownload(item, new OnCmdCompletedListener() {
                    @Override
                    public void onCmdCompleted() {
                        DLog.e("onCompleted");
                    }
                });
            }
        });
        findViewById(R.id.btn1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(v.getContext(), DownloadManagerListActivity.class));
            }
        });
        findViewById(R.id.btn2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DownloadDBItem item = new DownloadDBItem.Builder().setDownloadId("9").setTitle("xxx.apk").setUrl("https://pay.cnki.net/cnkiclientapp/CNKIClient_Version8.8.1.apk").builder();
                DownloadManager.getInstance().stopDownload(item);
                DownloadManager.getInstance().startDownload(item);
            }
        });


    }
}